package org.icec.iot.mqtt.server.plugin.auth;

import org.icec.iot.mqtt.server.common.auth.ClientBean;
import org.icec.iot.mqtt.server.common.auth.IAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

/**
 * 基于数据库的用户验证
 * 
 * @author loongsec
 *
 */
@Service("dbAuthService")
@Slf4j
public class DbAuthService implements IAuthService {
	@Autowired
	private AuthDao authDao;

	@Override
	public boolean checkValid(ClientBean bean) {
		try {
			ClientBean client = authDao.check(bean.getName(), bean.getPasswd());
			if (client != null) {
				bean.setRole(client.getRole());
				return true;
			}
		}catch(Exception e) {
			log.error("登录权限认证异常",e);
		}
		return false;
	}

}
